<template>
  <van-pull-refresh class="me-refresh" v-model="isRefresh" @refresh="onRefresh">
    <div class="statistics-wrap">
      <div class="title">
        <span>资金明细</span>
      </div>
      <div class="statistics-content" v-if="showFlag">
        <div class="card">
          <div class="top">
            <p>
              <span>{{capitalData.user_total_money.word || '用户总资产（元）'}}</span>
              <img class="question-mark" src="../../assets/capital/icon6.png" alt />
            </p>
            <count-to
              :start-val="0"
              :decimals="2"
              :end-val="+capitalData.user_total_money.value || 0"
              :duration="300"
              class="card-panel-num"
            />
          </div>

          <div class="list" v-if="capitalData.wallet_list.length > 0">
            <div class="item" v-for="(item,index) in capitalData.wallet_list" :key="index">
              <p>{{item.wallet_total_money.word}}</p>
              <count-to
                :start-val="0"
                :decimals="2"
                :end-val="+item.wallet_total_money.value || 0"
                :duration="300"
                class="card-panel-num"
              />
            </div>
          </div>
          <div v-else class="list-noTip">
            <span>暂无数据</span>
          </div>
        </div>
        <div class="wallet">
          <div class="common-title">
            <span>钱包统计</span>
          </div>
          <div class="content" v-if="capitalData.wallet_list.length > 0">
            <van-swipe class="my-swipe" indicator-color="white" :loop="false">
              <van-swipe-item
                class="my-swipe-item"
                v-for="(item,index) in capitalData.wallet_list"
                :key="index"
              >
                <div class="content-title">
                  <p>{{item.wallet_total_money.word}}</p>
                  <count-to
                    :start-val="0"
                    :decimals="2"
                    :end-val="+item.wallet_total_money.value || 0"
                    :duration="300"
                    class="card-panel-num"
                  />
                  <img class="question-mark" src="../../assets/capital/icon6.png" alt />
                </div>

                <div class="echarts-wrap">
                  <div class="echarts-box" v-if="chartFlag" ref="echartsBox">
                    <span class="echarts-tips">资金占比</span>
                    <WalletChart ref="WalletChart" :capitalData="item.wallet_item_money" />
                  </div>
                  <div class="echarts-txt">
                    <div
                      class="echarts-txt-item"
                      v-for="(item,index) in item.wallet_item_money"
                      :key="index"
                    >
                      <p>
                        <i class="txt-block"></i>
                        {{item.word}}
                      </p>
                      <count-to
                        :start-val="0"
                        :decimals="2"
                        :end-val="+item.value || 0"
                        :duration="300"
                        class="card-panel-num"
                      />
                    </div>
                  </div>
                </div>

                <div class="other-list">
                  <div
                    class="other-item"
                    v-for="(item,index) in item.wallet_total_statistics"
                    :key="index"
                  >
                    <p>{{item.word}}</p>
                    <count-to
                      :start-val="0"
                      :decimals="2"
                      :end-val="+item.value || 0"
                      :duration="300"
                      class="card-panel-num"
                    />
                  </div>
                </div>
              </van-swipe-item>
            </van-swipe>
          </div>

          <div v-else class="list-noTip">
            <span>暂无数据</span>
          </div>
        </div>

        <div class="user">
          <div class="common-title">
            <span>用户统计</span>
          </div>
          <div class="user-list" v-if="capitalData.user_total_list.length > 0">
            <div class="user-item" v-for="(item,index) in capitalData.user_total_list" :key="index">
              <img v-if="item.word == '累计充值'" src="../../assets/capital/icon7.png" alt />
              <img v-else src="../../assets/capital/icon8.png" alt />
              <p>{{item.word}}</p>
              <count-to
                :start-val="0"
                :decimals="2"
                :end-val="+item.value || 0"
                :duration="300"
                class="card-panel-num"
              />
            </div>
          </div>
          <div v-else class="list-noTip">
            <span>暂无数据</span>
          </div>
        </div>
      </div>
    </div>
  </van-pull-refresh>
</template>

<script>
import CountTo from "vue-count-to";
import { getStatistics } from "@/api/capital";
import WalletChart from "./components/wallet-chart";
export default {
  components: {
    CountTo,
    WalletChart,
  },
  data() {
    return {
      isRefresh: false,
      chartFlag: false,
      showFlag: false,
      capitalData: {},
      widthData: "",
    };
  },
  created() {
    this.$toast.loading({
      duration: 0,
      message: "数据加载中",
      forbidClick: true,
      loadingType: "spinner",
    });
    this._getStatistics();
  },
  methods: {
    // 下拉刷新
    onRefresh() {
      this.chartFlag = false;
      this._getStatistics();
    },
    // 获取资金统计数据
    _getStatistics() {
      getStatistics()
        .then((res) => {
          if (res.code == 1 && res.data) {
            this.capitalData = res.data;
            this.chartFlag = true;
            this.showFlag = true;
            console.log("资金统计数据", this.capitalData);
          } else {
            this.chartFlag = false;
            Notify({
              type: "warning",
              message: res.mag || "资金数据获取失败，请稍后再试",
            });
            console.log("资金统计请求错误", res.msg || "请求失败");
          }
        })
        .catch((error) => {
          reject(error);
          this.chartFlag = false;
          Notify({
            type: "warning",
            message: res.mag || "资金数据获取失败，请稍后再试",
          });
        })
        .finally(() => {
          this.$toast.clear();
          this.isRefresh = false;
        });
    },
  },
};
</script>

<style lang="scss">
.statistics-wrap {
  .my-swipe {
    padding-bottom: 60px;
    .van-swipe__indicators {
      bottom: 0;
      // width: 32px;
      height: 12px;
      background: #dcdcdc;
      box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.1);
      border-radius: 12px;
      padding: 3px 7px;
      .van-swipe__indicator {
        background-color: #b5b5b5;
        &.van-swipe__indicator--active {
          background-color: #f4640e !important;
        }
      }
    }
  }
}
</style>

<style lang='scss' scoped>
.statistics-wrap {
  width: 100%;
  min-height: 100vh;
  background-color: #f7f7f7;
  background-image: url("../../assets/capital/bg1.png");
  background-repeat: no-repeat;
  background-position: 0 0;
  background-size: 100% 18%;
  overflow: auto;
  text-align: left;
  .common-title {
    font-size: 28px;
    color: #333;
    font-weight: bolder;
    padding: 24px 2%;
    letter-spacing: 2px;
    span {
      position: relative;
      &::after {
        content: "";
        width: 100%;
        height: 10px;
        background: rgba(244, 100, 14, 0.4);
        position: absolute;
        bottom: 2px;
        left: 0;
        border-radius: 2px;
      }
    }
  }
  .question-mark {
    width: 26px;
    height: 26px;
    display: none;
  }
  .title {
    width: 100%;
    text-align: right;
    padding: 40px;
    span {
      font-size: 24px;
      color: #fff;
      letter-spacing: 3px;
      opacity: 0;
    }
  }
  .card {
    width: 92%;
    background: #fff;
    box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    margin: 0 auto;
    text-align: left;
    overflow: hidden;
    margin-bottom: 20px;
    .top {
      padding: 28px 24px 22px 24px;
      border-bottom: 2px solid #f9f9f9;
      p {
        display: flex;
        justify-content: space-between;
        margin-bottom: 34px;
        span {
          font-size: 24px;
          color: #666666;
        }
      }
      .card-panel-num {
        font-size: 44px;
        font-weight: bolder;
        color: #121212;
      }
    }
    .list {
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      overflow: hidden;
      .item {
        width: 50%;
        border-bottom: 2px solid #f9f9f9;
        border-right: 2px solid #f9f9f9;
        padding: 22px 24px;
        box-sizing: border-box;
        p {
          font-size: 24px;
          color: #121212;
          padding-bottom: 22px;
        }
        .card-panel-num {
          font-size: 28px;
          color: #8e8e8e;
        }
      }
    }
  }

  .wallet {
    width: 92%;
    margin: 0 auto;
    .content {
      .my-swipe {
        width: 100%;
        .my-swipe-item {
          background: #fff;
          box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.1);
          border-radius: 10px;
          padding: 25px 18px 50px 25px;
          min-height: 860px;
          .content-title {
            color: #121212;
            display: flex;
            position: relative;
            margin-bottom: 50px;
            p {
              font-size: 28px;
              font-weight: 500;
            }
            .card-panel-num {
              font-size: 30px;
              font-weight: 800;
              padding-left: 100px;
            }
            .question-mark {
              position: absolute;
              top: 46%;
              right: 0;
              transform: translateY(-50%);
            }
          }
          .echarts-wrap {
            width: 100%;
            height: 400px;
            border-bottom: 2px solid #f2f2f2;
            position: relative;
            .echarts-box {
              // width: 100%;
              height: 100%;
              position: absolute;
              top: 0;
              left: 0;
              z-index: 22;
              .echarts-tips {
                // display: inline-block;
                // width: 215px;
                // height: 215px;
                // border: 30px solid #f9f9fb;
                // border-radius: 50%;
                // line-height: 215px;
                //  text-align: center;
                font-size: 22px;
                color: #8e8e8e;
                position: absolute;
                top: 50%;
                left: 27%;
                transform: translate(-50%, -50%);
              }
            }
            .echarts-txt {
              position: relative;
              z-index: 11;
              left: 62%;
              top: 45px;
              .echarts-txt-item {
                margin-bottom: 25px;
                &:last-of-type {
                  margin: 0;
                }
                p {
                  font-size: 22px;
                  color: #8e8e8e;
                  padding-bottom: 10px;
                  position: relative;
                  i {
                    display: inline-block;
                    width: 14px;
                    height: 14px;
                    background: #f4640e;
                    position: relative;
                    bottom: 2px;
                    margin-right: 10px;
                  }
                }
                .card-panel-num {
                  font-size: 24px;
                  color: #333333;
                  padding-left: 24px;
                }
                &:nth-of-type(2) {
                  i {
                    background: #057a83;
                  }
                }
                &:nth-of-type(3) {
                  i {
                    background: #425563;
                  }
                }
                &:nth-of-type(4) {
                  i {
                    background: #bfa8a2;
                  }
                }
              }
            }
          }
          .other-list {
            padding-top: 40px;
            font-size: 24px;
            color: #333;
            .other-item {
              padding-bottom: 33px;
              display: flex;
              justify-content: space-between;
              &:last-of-type {
                padding: 0;
              }
            }
          }
        }
      }
    }
  }
  .user {
    width: 92%;
    margin: 0 auto;
    font-size: 24px;
    .user-list {
      margin-top: 20px;
      .user-item {
        padding-bottom: 40px;
        display: flex;
        line-height: 45px;
        img {
          width: 45px;
          height: 45px;
          margin-right: 15px;
        }
        .card-panel-num {
          margin-left: auto;
        }
      }
    }
  }
  .list-noTip {
    text-align: center;
    line-height: 140px;
    color: #ccc;
  }
}
</style>